// const { utils } = require("webpack-cli");

/**
 * 工具函数
 */

/**
*@prompt
*/
function clearprompt(status = 0, msg = '操作失败') {
  let div = document.createElement('div');
  div.innerHTML = `
<div class="prompt">
<!-- 标志 -->
<div class="gou">
    ${status == 0 ? '√' : '!'}
</div>
<!-- 提示信息 -->
<div class="prompt-text">
${msg}
</div>
</div>
`;
  let body = document.querySelector('body')
  document.body.appendChild(div);
  setInterval(function () {
    div.remove()
  }, 2000)
}

/**
 * @createFooter
 * 
 * 
 */ 
 function createFooter(page = 'home') {
  let footer = document.createElement('footer');
  footer.className = 'dpflex jsaround';
  footer.innerHTML = `
     <a href="./home.html">
      <div class="${page === 'home' ? 'active' : ''}">
        <i class="iconfont icon-xiazai45"></i>
        <p>首页</p>
      </div>
     </a>
      <a href="./sports.html">
        <div class="${page === 'sports' ? 'active' : ''}"> 
          <i class="iconfont icon-yundong-"></i>
          <p> 运动</p>
        </div>
       </a>
      <a href="./mine.html">
          <div class="${page === 'mine' ? 'active' : ''}">
          <i class="iconfont icon-wode"></i>
          <p>我的</p>  
        </div>
      </a>
    `
  document.body.appendChild(footer);
}

/**
   * 封装调用本地时间函数
   *@forGetTime
   *@date  传入参数为new Date()或者'1990-01-02'格式
   * 作者：kasswoler
   * 时间：2022年1月2日
   * */
   function forGetTime(date,choose=0){
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    let hour = date.getHours();
    let min = date.getMinutes();
    let sec = date.getSeconds();
    if(choose==0){
      let str = `${year}-${month > 10 ? "" : 0}${month}-${
        day > 10 ? "" : 0
      }${day} ${hour > 10 ? "" : 0}${hour}:${min > 10 ? "" : 0}${min}:${
        sec > 10 ? "" : 0
      }${sec}`;
      return str;
    }else if(choose===1){
      let str = `${year}-${month > 10 ? "" : 0}${month}-${
        day > 10 ? "" : 0
      }${day} `;
      return str;
    }
    
  }



window.utils = {
  createFooter,
  clearprompt,
  forGetTime,
}